package com.xwj.validation.nest.controller;

import com.alibaba.fastjson.JSON;
import com.xwj.common.util.R;
import com.xwj.validation.nest.dto.StudentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author: xiaowajiang
 * @Date: 2022-03-13 20:41
 * @Description: 嵌套校验
 **/
@Slf4j
@RestController
@Api(value = "NestValidController", tags = "嵌套校验")
public class NestValidController {

    @ApiOperation(value = "嵌套数据接口校验", notes = "请求体发送的 JSON 数据，存在嵌套对象。校验失败后，抛出 MethodArgumentNotValidException 异常")
    @PostMapping("nest/valid/student/saveStudent")
    public R saveStudent(@Valid @RequestBody StudentDTO stu) {
        log.info("保存学员信息，入参：{}", JSON.toJSONString(stu));
        // 业务逻辑
        return R.ok();
    }

}
